package com.lanhe.admin.controller.weightAssistant;


import com.lanhe.common.annotation.Log;
import com.lanhe.common.core.controller.BaseController;
import com.lanhe.common.core.domain.AjaxResult;
import com.lanhe.common.core.page.TableDataInfo;
import com.lanhe.common.enums.BusinessType;
import com.lanhe.weightAssistant.domain.LhWeightAssistant;
import com.lanhe.weightAssistant.service.ILhWeightAssistantService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 权重助手管理(LhWeightAssistant)表控制层
 *
 * @author zhanggl
 * @since 2023-12-30 14:02:30
 */
@RestController
@RequestMapping("lhWeightAssistant")
public class LhWeightAssistantController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ILhWeightAssistantService lhWeightAssistantService;

    /**
     * 分页查询所有数据
     */
    @PreAuthorize("@ss.hasPermi('weightAssistant:weightAssistant:list')")
    @GetMapping("/list")
    public TableDataInfo list(LhWeightAssistant weightAssistant) {
        startPage();
        List<LhWeightAssistant> list = lhWeightAssistantService.selectWeightAssistantList(weightAssistant);
        return getDataTable(list);
    }

    /**
     * 根据编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('weightAssistant:weightAssistant:query')")
    @GetMapping(value = {"/", "/{weightAssistantId}"})
    public AjaxResult getInfo(@PathVariable(value = "weightAssistantId") Long weightAssistantId) {
        return success(lhWeightAssistantService.selectWeightAssistantById(weightAssistantId));
    }

    /**
     * 新增权重助手
     */
    @PreAuthorize("@ss.hasPermi('weightAssistant:weightAssistant:add')")
    @Transactional
    @Log(title = "权重助手管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody LhWeightAssistant weightAssistant) {

        weightAssistant.setCreateBy(getUsername());
        weightAssistant.setCreateTime(new Date());
        return toAjax(lhWeightAssistantService.insertWeightAssistant(weightAssistant));
    }

    /**
     * 修改权重助手
     */
    @PreAuthorize("@ss.hasPermi('weightAssistant:weightAssistant:edit')")
    @Log(title = "权重助手管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody LhWeightAssistant weightAssistant) {
        if (ObjectUtils.isEmpty(weightAssistant.getWeightAssistantId())
                || null == weightAssistant.getWeightAssistantId()) {
            return error("主键ID不能为空");
        }
        weightAssistant.setUpdateBy(getUsername());
        weightAssistant.setUpdateTime(new Date());
        return toAjax(lhWeightAssistantService.updateWeightAssistant(weightAssistant));
    }

    /**
     * 删除权重助手
     */
    @PreAuthorize("@ss.hasPermi('weightAssistant:weightAssistant:remove')")
    @Log(title = "权重助手管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{assistantIds}")
    public AjaxResult remove(@PathVariable Long[] assistantIds)
    {
        if (ObjectUtils.isEmpty(assistantIds)){
            return error("主键ID不能为空");
        }
        return toAjax(lhWeightAssistantService.deleteWeightAssistantByIds(assistantIds));
    }
}

